---@class UIMaintenanceMsg : UIBase
UIMaintenanceMsg = UIBase.New(PanelResNames.UIMaintenanceMsg)
local t = UIMaintenanceMsg

function t.Init(noticeText,openTime,updateType,updateUrl)
    t.noticeText = noticeText
    t.openTime = openTime
    t.updateType = updateType
    t.updateUrl = updateUrl
    UIBase.Init(t)
end

function t:OnCreate()
    local msg = self:GetChild("Text")
    self.title = self:GetChild("TitleLb")
    self.content = self:GetChild("Text",msg)
    self.cdTitle = self:GetChild("CdTitle",msg)
    self.cdText = self:GetChild("Cd",msg)
    self.sureBtn = self:GetChild("CloseBtn1")
    self.CloseBtn2 = self:GetChild("CloseBtn2")
    self.UpdateBtn = self:GetChild("UpdateBtn")
    self.ctrlType = self:GetController("type")
    self.maintenanceText = self:GetChild("TextFU")
    self.ctrlType.selectedIndex = 1
    self:RegisterOnClick(self.sureBtn,self.ClickSure)
    self:RegisterOnClick(self.CloseBtn2,self.ClickUpdateClose)
    self:RegisterOnClick(self.UpdateBtn,self.ClickUpdate)

end

function t:OnEnable()
    self:Refresh()
end
function t:OnDisable()
end
function t:OnDestroy()
end
function t:ClickSure()
    closeUI(PanelNames.UIMaintenanceMsg)
end
function t:ClickUpdateClose()
    closeUI(PanelNames.UIMaintenanceMsg)
    LoginManager.QuitGame()
end
function t:ClickUpdate()
    UnityEngine.Application.OpenURL(t.updateUrl);
end
function t:Refresh()
    if t.updateType == EnumConst.MaintenanceUpdateType.maintenance then
        self.title.text = getLanguage("MaintenanceMsg_Title_Maintenance")
        self.cdTitle.text = getLanguage("MaintenanceMsg_Text_CD")
        self.ctrlType.selectedIndex = 0
        self.content.text = t.noticeText
        self:RefreshTime()
        self:TimeCall(self.RefreshTime,1000,-1)
    elseif t.updateType == EnumConst.MaintenanceUpdateType.forceUpdate then
        self.title.text = getLanguage("MaintenanceMsg_Title_Update")
        self.maintenanceText.text = getLanguage("MaintenanceMsg_Text_ForcedUpdate")
        self.ctrlType.selectedIndex = 1
    end
end
function t:RefreshTime()
    local time = t.openTime - os.time()
    if time < 0 then
        self:RemoveTimeCall(self.RefreshTime)
    end
    self.cdText.text = HelperFunc.GetTimeStr(time)
end
return t